import easygui as g
import os

#def filereplace(path,newpath):
#    f = open(path)
#    for eachline in f:
#        for each in eachline:
#            if each.isdigit():
#                each.replace(each,'')
            #new_name = os.path.join(path)
#            os.chdir(newpath)
#            new_f = open(path,'w')
#            new_f.write(each)
#            new_f.close()
#    f.close()

def search_file(start_dir,newpath):
    os.chdir(start_dir)

    for file_name in os.listdir(os.curdir):
        f = open(file_name)
        try:
            for eachline in f:
                for each in eachline:
                    if each.isdigit():
                        each = each.replace(each,'')
                    os.chdir(newpath)
                    new_f = open(file_name,'a')
                    new_f.write(each)
                    new_f.close()
        except UnicodeDecodeError:
            pass
        f.close()
        os.chdir(start_dir)

        if os.path.isdir(file_name):
            search_file(file_name)
            os.chdir(os.pardir)

g.msgbox('请打开需要变更的文件夹：')
start_dir = g.diropenbox('请打开需要变更的文件夹：')
g.msgbox('请打开需要保存变更后文件夹：(注意：若与第一次打开文件夹路径相同会覆盖原文件！)')
newpath = g.diropenbox('请打开需要保存变更后文件夹：')
search_file(start_dir,newpath)
    
